﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Srv3CodeTool
{
    public partial class FrmNewModule : Form
    {
        public FrmNewModule()
        {
            InitializeComponent();
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Functions func = new Functions();
                string[] szMsgArr = new string[lsvMsg.Items.Count];
                for (int i = 0; i < lsvMsg.Items.Count; ++i)
                {
                    szMsgArr[i] = lsvMsg.Items[i].ToString();
                }
                if (func.CreateNewModuleByMode(txtModuleName.Text.ToString(), szMsgArr))
                {
                    Functions.ShowMsgBox("新模块创建成功", MSGBOX_TYPE.MSGBOX_TYPE_INFO);
                }
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }

        private void FrmNewModule_Load(object sender, EventArgs e)
        {
            try
            {
                Functions func = new Functions();
                object[] objMsgArr = func.GetMsgArray();
                cmbNewMsg.Items.AddRange(objMsgArr);
                cmbNewMsg.SelectedIndex = 0;
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem myItem = new ListViewItem();
                myItem = lsvMsg.Items.Add(cmbNewMsg.SelectedItem.ToString());
                if (cbListen.Checked)
                    myItem.SubItems.Add("是");
                else
                    myItem.SubItems.Add("否");
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            try
            {
                lsvMsg.Items.Remove(lsvMsg.SelectedItems[0]);
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }
    }
}
